<%--
  Created by IntelliJ IDEA.
  User: Administrator
  Date: Jul 4, 2005
  Time: 5:58:36 PM
  To change this template use File | Settings | File Templates.
--%>
<%@ page language="java" %>
<%
   response.setHeader("Cache-Control", "no-cache");
   response.setHeader("Pragma", "no-cache");
   response.setDateHeader("max-age", 0);
   response.setDateHeader("Expires", 0);
%>

<%@ page import="com.scalar.chiptrack.utils.ConfigManager,
                com.scalar.chiptrack.users.User,
                com.scalar.chiptrack.commons.SessionKeys"%>
<%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html" %>
<%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %>
<%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic" %>
<%@ taglib uri="/WEB-INF/struts-nested.tld" prefix="nested" %>
<%@ taglib uri="/WEB-INF/chiptrack-tags.tld" prefix="chiptrack" %>

<%--<chiptrack:checkLogon sourcePage="/sortDataEntry.do"/>--%>
<%String chipTracContext = "/" + ConfigManager.getChipTracContext();%>


<html>

<HEAD>
<TITLE>ScalarSoft - ChipTrac - BOM Bin Data Entry </TITLE>
   <META http-equiv='Content-Type' content='text/html; charset=windows-1252'>
   <LINK href='<%=chipTracContext%>/jsp/includes/stylesheets/scalarsoft.css' type='text/css' rel='stylesheet'>
<script src="<%=chipTracContext%>/jsp/includes/scripts/validations.js"></script>
   <script language='javascript' >

function resetValues()
   {
       document.binDataEntryform.reset();
   }

function save()
{
    errors  = "";
    var pa  = document.getElementById("message");
    success = false;
    form		= document.binDataEntryform;
    openerform	= window.opener.document;
    qtyOut	= form.qtyOut.value;
    for ( i = 0; i < qtyOut; i++ )
    {
        if ( form['bomLotBinData['+i+'].waferId'].value.trim() == "" )
        {
            errors = "Wafer Id cannot be blank for Sl No."+ ( i + 1 );
            pa.innerHTML = errors;
            success = false;
            break;
        }
    }
    if( errors == "" )
    {
        for ( i = 0; i < qtyOut - 1; i++ )
        {
            for ( j = i + 1; j < qtyOut; j++ )
            {
                if ( form['bomLotBinData['+i+'].waferId'].value != "" && form['bomLotBinData['+j+'].waferId'].value != "" && form['bomLotBinData['+i+'].waferId'].value == form['bomLotBinData['+j+'].waferId'].value )
                {
                    errors = "Wafer Id's of two Wafer's should not be same.";
                    pa.innerHTML = errors;
                    success = false;
                }
            }
        }
        if( form.lotId.value != -1 )
        {
            for ( i = 0; i < qtyOut; i++ )
            {
                if( parseInt(form["bin1BalanceQty"+i].value) - (parseInt(form['bomLotBinData['+i+'].bin1Qty'].defaultValue) - parseInt(form['bomLotBinData['+i+'].bin1Qty'].value)) < 0 )
                {
                    errors = "Bin1 Quantity can not be less than Bin1 Pulled Quantity("+(parseInt(form['bomLotBinData['+i+'].bin1Qty'].defaultValue) -  parseInt(form["bin1BalanceQty"+i].value))+") for Wafer Id :"+form['bomLotBinData['+i+'].waferId'].value;
                    pa.innerHTML = errors;
                    success = false;
                }
            }
        }
        if( errors == "" )
        {
            success = true;
        }
    }
    if( success == true )
    {
        if( form.lotId.value != -1 )
        {
            for ( i = 0; i < qtyOut; i++ )
            {
                form['bomLotBinData['+i+'].bin1Qty'].disabled = false;
                form['bomLotBinData['+i+'].bin1BalanceQty'].disabled = false;
                form['bomLotBinData['+i+'].scrap'].disabled = false;
            }
        }
        form.action = '<%=chipTracContext%>/bomBinLotDataEntry.do?action=saveBomBinDataEntry&quantityOut='+qtyOut;
        form.submit();
    }
}

//window.onunload = closeWindow;

function closeWindow()
{
    window.opener.refreshParent();
    window.close();
}

function resetbalanceqty(index)
{
  var form = document.binDataEntryform
  if( form['bomLotBinData['+index+'].scrap'].checked == true )
  {
    form['bomLotBinData['+index+'].bin1BalanceQty'].value = 0
  }
  else
  {
    var bin1Qty = form['bomLotBinData['+index+'].bin1Qty'].value;
    var bin1DefaultQty = form['bomLotBinData['+index+'].bin1Qty'].defaultValue;
    if( parseInt(bin1Qty) > parseInt(bin1DefaultQty) )
    {
        form['bomLotBinData['+index+'].bin1BalanceQty'].value = parseInt(form["bin1BalanceQty"+index].value) + (parseInt(bin1Qty) - parseInt(bin1DefaultQty)) ;
    }
    else
    {
        form['bomLotBinData['+index+'].bin1BalanceQty'].value = parseInt(form["bin1BalanceQty"+index].value) - (parseInt(bin1DefaultQty) - parseInt(bin1Qty)) ;
    }
  }

}

function populateBalanceQty( idx )
{
  var form = document.binDataEntryform;
  var pa  = document.getElementById("message");
  if( form['bomLotBinData['+idx+'].scrap'].checked == false )
  {
    var bin1Qty = form['bomLotBinData['+idx+'].bin1Qty'].value;
    var bin1DefaultQty = form['bomLotBinData['+idx+'].bin1Qty'].defaultValue;
    if(bin1DefaultQty == '')
    {
        form['bomLotBinData['+idx+'].bin1BalanceQty'].value = bin1Qty;
    }
    else
    {
        if( parseInt(bin1Qty) > parseInt(bin1DefaultQty) )
        {
            form['bomLotBinData['+idx+'].bin1BalanceQty'].value = parseInt(form["bin1BalanceQty"+idx].value) + (parseInt(bin1Qty) - parseInt(bin1DefaultQty)) ;
            pa.innerHTML = "";
        }
        else
        {   if( parseInt(form["bin1BalanceQty"+idx].value) - (parseInt(bin1DefaultQty) - parseInt(bin1Qty)) < 0 )
            {
                errors = "Bin1 Quantity can not be less than Bin1 Pulled Quantity("+((parseInt(bin1DefaultQty)) -  parseInt(form["bin1BalanceQty"+idx].value))+") for Wafer Id :"+form['bomLotBinData['+idx+'].waferId'].value;
                pa.innerHTML = errors;
                return;
            }
            else
            {
                form['bomLotBinData['+idx+'].bin1BalanceQty'].value = parseInt(form["bin1BalanceQty"+idx].value) - (parseInt(bin1DefaultQty) - parseInt(bin1Qty)) ;
                pa.innerHTML = "";
            }
        }
    }

  }
}
   </script>
</HEAD>
<%
   User user = ( User ) session.getAttribute ( SessionKeys.USER_KEY );
   if ( user != null )
   {
%>
<logic:notPresent name="isSaved">
    <BODY bgcolor='ffffff' marginheight='0' marginwidth='0' topmargin='0' leftmargin='0'>
</logic:notPresent>
<logic:present name="isSaved">
    <BODY bgcolor='ffffff' marginheight='0' marginwidth='0' topmargin='0' leftmargin='0' onload="javascript:closeWindow()">
</logic:present>
<html:form name="binDataEntryform" action="bomDataEntry" type="com.scalar.chiptrack.operations.dataentry.forms.BOMDataEntryForm">
<table align='center' border='0' width='100%' >
    <tr>
        <td align='center' class="NArialL">BOM Bin Data Entry</td>
    </tr>
    <tr>
        <td align='center'>&nbsp;</td>
    </tr>
    <logic:present name="isSaved">
       <tr>
           <td align='center'><font class="NArialL"> <font color="green">BOM Bin Lot Data Saved </font></font></td>
       </tr>
       <tr>
           <td align='center'><a href="javascript:closeWindow()" title='Click here to close the window'><img border="0" src="<%=chipTracContext%>/jsp/includes/images/cancel.gif" ></a></td>
       </tr>
    </logic:present>
    <logic:notPresent name="isSaved">
    <%
        String qtyOut = (String) request.getAttribute("quantityOut");
        int qtyOut_i;
        try
        {
            qtyOut_i = Integer.parseInt( qtyOut);
        }
        catch( NumberFormatException e)
        {
            qtyOut_i = 0;
        }
    %>
       <tr><td align='center'>
        <table align="center" border="0" width="80%">
            <INPUT TYPE="HIDDEN" NAME="qtyOut" value="<%=qtyOut_i%>"/>
            <html:hidden name='binDataEntryform' property='lotId'/>
            <tr>
                <td colspan="6" width="100%" class="NArialL">&nbsp;<FONT id="message" size=1 color='FF0000'></FONT></td>
            </tr>
                <tr> <td align='center' bgcolor="#993333"><font class="NArialL"><font color="#FFFFFF"> SL.No </font></font></td>
                <td align='center' bgcolor="#993333"><font class="NArialL"><font color="#FFFFFF"> Wafer Id *</font></font></td>
                <td align='center' bgcolor="#993333"><font class="NArialL"><font color="#FFFFFF">Bin1 Quantity</font></font></td>
                <logic:notEqual name='binDataEntryform' property='lotId' value='-1'>
                    <td align='center' bgcolor="#993333"><font class="NArialL"><font color="#FFFFFF">Bin1 Balance Quantity</font></font></td>
                    <td align='center' bgcolor="#993333"><font class="NArialL"><font color="#FFFFFF">Scrap</font></font></td>
                </logic:notEqual>
            </tr>
       <nested:iterate id="binData" property="bomLotBinData" type="com.scalar.chiptrack.operations.dataentry.BOMLotBinData" indexId="idx" >
            <tr>
                <nested:equal property="scrap" value="true" >
                    <td align='center'><font class="NArialL"><bean:write name="binData" property="serialNo"/></font></td>
                    <td align='center'><font class="NArialL"><nested:text name="binData" property="waferId" styleClass="txfield" disabled='true'/></font></td>
                    <td align='center'><font class="NArialL"><nested:text name="binData" property="bin1Qty" styleClass="txfield" disabled='true'/></font></td>
                    <td align='center'><font class="NArialL"><nested:text name="binData" property="bin1BalanceQty" styleClass="txfield" disabled='true'/></font></td>
                    <input type ='hidden' name="bin1BalanceQty<%=idx%>" value='<nested:write  name="binData" property="bin1BalanceQty"/>'/>
                    <td align='center'><font class="NArialL"><nested:checkbox property="scrap" styleClass="txfield" disabled='true'/></font></td>
                </nested:equal>
                <nested:notEqual property="scrap" value="true" >
                    <td align='center'><font class="NArialL"><bean:write name="binData" property="serialNo"/></font></td>
                    <logic:equal name='binDataEntryform' property='lotId' value='-1'>
                        <td align='center'><font class="NArialL"><nested:text name="binData" property="waferId" styleClass="txfield" onkeypress="allowInteger()"/></font></td>
                        <td align='center'><font class="NArialL"><nested:text name="binData" property="bin1Qty" styleClass="txfield"/></font></td>
                    </logic:equal>
                    <logic:notEqual name='binDataEntryform' property='lotId' value='-1'>
                        <%
                        String js = "populateBalanceQty("+idx+")";
                        %>
                        <td align='center'><font class="NArialL"><nested:text name="binData" property="waferId" styleClass="txfield" disabled='true'/></font></td>
                        <td align='center'><font class="NArialL"><nested:text name="binData" property="bin1Qty" styleClass="txfield" onchange="<%=js%>"/></font></td>
                        <td align='center'><font class="NArialL"><nested:text name="binData" property="bin1BalanceQty" styleClass="txfield" disabled='true'/></font></td>
                        <input type ='hidden' name="bin1BalanceQty<%=idx%>" value='<nested:write  name="binData" property="bin1BalanceQty"/>'/>
                        <%
                            js = "resetbalanceqty("+idx+")";
                        %>
                        <nested:notEqual property="disabled" value="true" >
                            <td align='center'><font class="NArialL"><nested:checkbox property="scrap" styleClass="txfield" onclick="<%=js%>"/></font></td>
                        </nested:notEqual>
                        <nested:equal property="disabled" value="true" >
                            <td align='center'><font class="NArialL"><nested:checkbox property="scrap" styleClass="txfield" disabled='true'/></font></td>
                        </nested:equal>
                    </logic:notEqual>
                </nested:notEqual>
            </tr>
       </nested:iterate>
       </table>
       </td></tr>
       <tr><td align='center'>&nbsp;</td></tr>
       <tr>
       <td align='center'>
           <a href="javascript:save()" title='Click here to Save Sort Bin Data Entry'><img border="0" src="<%=chipTracContext%>/jsp/includes/images/save.gif" ></a>&nbsp;&nbsp;&nbsp;
           <a href="javascript:resetValues()" title='Click here to reset all field values'><img border="0" src="<%=chipTracContext%>/jsp/includes/images/reset.gif" ></a>&nbsp;&nbsp;&nbsp;
           <a href="javascript:closeWindow()" title='Click here to close the window'><img border="0" src="<%=chipTracContext%>/jsp/includes/images/cancel.gif" ></a>
       </td>
       </tr>
       </logic:notPresent>
</table>
</html:form>
</body>
        <%
           }
           else{
       %>
   <BODY bgcolor='ffffff' marginheight='0' marginwidth='0' topmargin='0' leftmargin='0' >
   <table cellpadding='0' cellspacing='0' bgcolor='FDF5E6' border="0" width="100%"  height="100%" align=center>
       <tr>
           <td>
               <table align="center" border="0" width="40%" bgcolor="#FDF5E6">
                   <tr><td>&nbsp;</td></tr>
                   <tr><td align="center" ><font class="NArialL" ><font color="red"><b>Session has been time out , Please close this window and login again.<b></font></font></td></tr>
                   <tr><td>&nbsp;</td></tr>
                   <tr><td align="center" ><a href="javascript:window.close();"><font class='NArialL'>[Close this window]</font></a></td></tr>
               </table>
           </td>
      </tr>
      <tr><td>&nbsp;</td></tr>
   </table>
   </body>
<% } %>
</html>
